/**
 * 
 */
package com.risetek.tft.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.risetek.tft.entity.TOperate;
import com.risetek.tft.entity.TOperateId;
import com.risetek.tft.service.OperateService;
import com.zlinepay.framework.service.impl.EntityServiceImpl;

/**
 * @author  hetao
 * 
 */
@Service
public class OperateServiceImpl extends EntityServiceImpl<TOperate> implements
		OperateService {
	public TOperate getOperateInPermission(TOperateId operateid,
			Integer accountid) {
		String hql = "select a from TOperate a join a.TRoles b join b.TManagers c where a.id.menu=? and a.id.op=? and c.managerid=?";
		return (TOperate) this.queryForObject(hql, operateid.getMenu(),
				operateid.getOp(), accountid);
	}

	public List<TOperate> getOperatesInPermissionByMenu(Integer menuid,
			Integer accountid) {
		String hql = "select a from TOperate a join a.TRoles b join b.TManagers c where a.id.menu=? and c.managerid=? order by a.ordno";
		return find(hql, menuid, accountid);
	}

	public boolean checkPermission(TOperateId operateid, Integer accountid) {
		String hql = "select a from TOperate a join a.TRoles b join b.TManagers c where a.id.menu=? and a.id.op=? and c.managerid=?";
		TOperate operate = (TOperate) queryForObject(hql, operateid.getMenu(), operateid.getOp(), accountid);
		return operate != null;
	}

}
